#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>
#include<sys/types.h>
#include<sys/wait.h>

int main()
{
    putenv("private_env=666666");
    extern char **environ;
    pid_t id=fork();
    if(id==0){//子进程成功创建
//        char *const myargv[]={
//            "ls",
//            "-l",
//            "-a",
//            NULL
//        };
        
    char*const myargv[]={
        "otherexe",
            "-a",
            "-b",
            "-c",
            NULL
    };

    char *const myenv[]={
        "my_val=520",
         "my_path=/usr/bin/xxx",
         NULL
    };
        printf("before: I am process,pid:%d,ppid:%d\n",getpid(),getppid());
       // execl("/usr/bin/ls","ls","-a","-l",NULL);
         // execvp("ls",myargv);
       // execve("./otherexe",myargv,environ);
        execve("./otherexe",myargv,myenv);
        printf("after: I am a process,pid:%d,ppid:%d\n",getpid(),getppid());
        exit(1);//用来标识是否替换成功
    }
    pid_t ret=waitpid(id,NULL,0);
    if(ret>0) printf("wait success,father pid:%d,ppid:%d\n",getpid(),getppid());
    sleep(3);
    return 0;
}
